﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using B2B.Models;

namespace B2B.Controllers
{
    public class AdminController : AlibabaApplicationController
    {
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult AdminManagePostBuyRequest(int id, int XoaMaSanPhamMua)
        {
            int page = id;
            Models.PostBuyRequest pbr = new Models.PostBuyRequest();
            if (XoaMaSanPhamMua != 0)
            {
                pbr.XoaSanPhamMua(XoaMaSanPhamMua);
            }
            ViewData["page"] = page;

            ArrayList list = pbr.DanhSachSanPhamMua_Admin(page);
            ViewData["ds_SanPhamMua"] = list;
            ViewData["tongDong"] = pbr.TongSanPham();
            return View();
        }

        public ActionResult AdminUpdatePostBuyRequest(int id, int TinhTrang)
        {
            int MaSanPhamMua = id;
            Models.PostBuyRequest pbr = new Models.PostBuyRequest();
            int kq = pbr.CapNhatTinhTrang(MaSanPhamMua, TinhTrang);
            ArrayList list = LaySanPhamMuaTheoMa(MaSanPhamMua);
            ViewData["SPMua"] = list;
            return View();
        }

        public ArrayList LaySanPhamMuaTheoMa(int id)
        {
            Models.PostBuyRequest pbr = new Models.PostBuyRequest();
            ArrayList list = pbr.LaySanPhamMuaTheoMa(id);
            return list;
        }

        public ActionResult AdminManageProduct(int id)
        {
            int page = id;
            ViewData["page"] = page;

            Models.SanPham sp = new Models.SanPham();
            ArrayList list_sp = sp.DanhSachSanPham(page);
            ViewData["DanhSachSanPham"] = list_sp;

            ViewData["TongSanPham"] = sp.TongSanPham();

            Models.QuocGia qg = new Models.QuocGia();
            ArrayList list_qg = qg.DanhSachQuocGia();
            ViewData["DanhSachQuocGia"]=list_qg;

            Models.ThanhVien tv = new Models.ThanhVien();
            ArrayList list_tv = tv.DanhSachThanhVienKhongPhanTrang();
            ViewData["DanhSachThanhVienKhongPhanTrang"] = list_tv;

            Models.DonViTinh dvt = new Models.DonViTinh();
            ArrayList list_dvt = dvt.DanhSachDonViTinh();
            ViewData["DanhSachDonViTinh"] = list_dvt;

            return View();
        }

        public ActionResult AdminUpdateProduct(int id, int TinhTrang)
        {
            Models.SanPham sp = new Models.SanPham();
            ViewData["SanPham"] = sp.LaySanPhamTheoMa(id);
            if (TinhTrang != -1)
            {
                int kq = sp.CapNhatSanPham(id, TinhTrang);
                ViewData["KetQuaCapNhat"] = kq;
            }
            return View();
        }

        public ActionResult AdminManageMember(ThanhVien id, int page)
        {
            ViewData["page"] = page;

            Models.ThanhVien tv = new Models.ThanhVien();
            ArrayList list_tv = tv.DanhSachThanhVien(page);
            ViewData["TongThanhVien"] = tv.TongThanhVien();
            ViewData["DanhSachThanhVien"] = list_tv;            
            Models.LoaiThanhVien ltv = new Models.LoaiThanhVien();
            ArrayList list_ltv = ltv.DanhSachLoaiTV();
            ViewData["DanhSachLoaiThanhVien"] = list_ltv;

            return View();
        }

        public ActionResult AdminUpdateMember(int id, int tinhtrang)
        {
            Models.ThanhVien tv = new Models.ThanhVien();
            ViewData["ThanhVien"] = tv.LayThanhVienTheoMa(id);
            int kq = -1;
            if (tinhtrang != -1)
            {
                kq = tv.CapNhatTinhTrangThanhVien(id, tinhtrang);
            }
            ViewData["KetQuaCapNhat"] = kq;
            return View();
        }

        public ActionResult AdminManageQuote(int id)
        {
     /*       int page = id;
            ViewData["page"] = page;

            Models.BaoGia bg = new Models.BaoGia();
            ArrayList list_bg = bg.DanhSachBaoGia(page);
            ViewData["TongBaoGia"] = bg.TongBaoGia();
            ViewData["DanhSachBaoGia"] = list_bg;
            //Models.LoaiThanhVien ltv = new Models.LoaiThanhVien();
            //ArrayList list_ltv = ltv.DanhSachLoaiTV();
            //ViewData["DanhSachLoaiThanhVien"] = list_ltv;
            */
            return View();
        }
    }
}
